$(document).ready( function() {
			// 选择地区
	var contractType = $("#contractType").val();
		
			$("#queryBtn").click(function(){
				$("#"+contractType+"Form").find("input[name='pageNo']").each(function(){
					$(this).val(1);
				});
				$("#"+contractType+"Form").submit();
			});
			
			
			
			var contextPath = Com_Parameter.ContextPath;
			var contractType = $("#contractType").val();
			var area = $("#area").val();
			var areaId = $("#areaId").val();
			if(area !="" && area!= null && areaId != "" && areaId !=null){
				$.get(contextPath + '/biz/contract/commonContract/'+ areaId + '/getStoreByAreaId', function(data) {
					var jsonObj = eval('(' + data + ')');
					for (var i = 0; i < jsonObj.length; i++) {
						var shop = jsonObj[i];
						$("#storeId").append("<option value='" + shop.code + "'>"+ shop.name + "</option>");
						$("#storeId").children("option").each(function() {
							if($(this).val() == storeId1){
								$(this).attr("selected","selected");
							}
						});
					}
				});
				$.get(contextPath + '/biz/contract/commonContract/'+ storeId1 + '/getFloorByStoreId', function(data) {
					var jsonObj = eval('(' + data + ')');
					for (var i = 0; i < jsonObj.length; i++) {
						var floor = jsonObj[i];
						$("#floorId").append("<option value='" + floor.code + "'>"+ floor.name + "</option>");
						$("#floorId").children("option").each(function() {
							if($(this).val() == floorId1){
								$(this).attr("selected","selected");
							}
						});
					}
				});
			}	
			var opt = {
				service : "selectOneRegionService",
				idField : "areaId",
				nameField : "area",
				title : "地区选择对话框"
			};
			$("#areaBtn").Dialog(opt);
			// 选取门店
			$("#area").blur(function() {
				var areaId = $("#areaId").val();
				if(areaId !="" && areaId !=null){
				$.get(contextPath + '/biz/contract/commonContract/'+ areaId + '/getStoreByAreaId', function(data) {
					var jsonObj = eval('(' + data + ')');
					$("#storeId").children("option").each(function() {
						$(this).remove();
					});
					$("#storeId").append("<option value=''>---请选择---</option>");
							for (var i = 0; i < jsonObj.length; i++) {
								var shop = jsonObj[i];
								$("#storeId").append("<option value='" + shop.code + "'>"+ shop.name + "</option>");
							}
						});
				}
			});
			// 选取楼层
			$("#storeId").change(function() {
					var storeId = $("#storeId").val();
					var store;
					$(this).children("option").each(function() {
						if ($(this).val() == storeId) {
							store = $(this).text();
						}
					});
					$("#store").val(store);
					if (storeId != "" && storeId != null) {
						$.get(contextPath + '/biz/contract/commonContract/'+ storeId + '/getFloorByStoreId', function(data) {
							var floorList = eval('(' + data + ')');
							$("#floorId").children("option").each(function() {
								$(this).remove();
							});
							$("#floorId").append("<option value=''>---请选择---</option>");
							for (var i = 0; i < floorList.length; i++) {
								var floor = floorList[i];
								$("#floorId").append("<option value='" + floor.code+ "'>" + floor.name+ "</option>");
							}
						});
					}
			});
			$("#floorId").change(function() {
				var floorId = $("#floorId").val();
				var floor;
				$(this).children("option").each(function() {
					if ($(this).val() == floorId) {
						floor = $(this).text();
					}
				});
				$("#floor").val(floor);
			});

			$("#serch").click(function() {
					$("#searchForm").attr("action","${contextPath}/biz/contract/" + contractType+ "/list");
			});
			$("#shopDialog").click(function(){
				var floorId=$("#floorId").attr("value");
				var storeId=$("#storeId").attr("value");
				if(floorId==null||floorId==''){
					$("#floor").focus();
					top.$.jBox.tip('楼层不能为空','warning');
					return false;
				}else{
					$("#modalBrand").load(contextpath+"/biz/contract/commonContract/showModal?floor="+floorId+"&siteid="+storeId,function(){
						
						 $("#modalBrand").modal("show");  
					}); 
				}
			});
			$("#storeId").change(function(){
				var store = $("#store").val();
				var storeId = $("#storeId").val();
			});
			
		});


function btn_onClick() {

	$("#myModal").load(
			contextPath + '/biz/contract/' + contractType
					+ '/getModuleContractList', function() {
				$("#myModal").modal("show");
			});
	$("#myModal").on('hidden.bs.modal', function(e) {

	});

}
function btnOK_click() {
	$("#ok").attr("data-dismiss", "modal");
	var ids = new Array(), i = 0;
	$('#modalTable').find("input[type='checkbox'][data-ckb-id]").each(
			function() {
				var $this = $(this);
				if ($this.prop('checked')) {
					ids.push($(this).attr("data-ckb-id"));
				}
			});
}



function Oosp_SubmitSap(href,tabId,urlParam){
	var ids = new Array();
	$('#'+tabId).find("input[type='checkbox'][data-ckb-id]").each(function(){
		var $this = $(this);
		if($this.prop('checked')){
			ids.push($(this).attr("data-ckb-id"))  ;
		}
	});
	if(ids.length==0){
		$.jBox.tip("请先勾选需要提交的数据！","${error}",{persistent:true,opacity:0});
	}else{
		top.$.jBox.confirm('确认要提交该条数据吗？','系统提示',function(v,h,f){
			if(v=='ok'){	
				Oosp_Loading('正在提交，请稍等...');
				if(urlParam){
					href = href.replace(urlParam,ids+'');
				}
				funform(href,'_self');
			}
		},{buttonsFocus:1});
	}
}


//清除所有条件
function cleanAll(){
	$("#signBy").val("");
	$("#signById").val("");
	$("#contractStatus").val("");
	$("#areaId").val("");
	$("#area").val("");
	$("#floorId").val("");
	$("#store").val("");
	$("#storeId").val("");
	$("#floor").val("");
	$("#contractAttribute").val("");
	$("#startDate").val("");
	$("#endDate").val("");
	$("#contractNo").val("");
	$("#intentNo").val("");
	$("#standardName").val("");
	$("#supplierName").val("");
	$("#supplierNo").val("");
	$("#nagNo").val("");
	$("#createTime").val("");
	$("#createById").val("");
	$("#historyContractNo").val("");
	$("#createBy").val("");
	$("#brandCName").val("");
	$("form").each(function(){
		$(this).find("select").each(function(){
			if($(this).attr("id")=="storeId" || $(this).attr("id")=="floorId"){
				$(this).find("option").each(function(){
					if($(this).attr("value") !=""){
						$(this).remove();
					}else{
						$(this).attr("selected","selected");
					}
				});
			}
			$(this).find("option").each(function(){
				if($(this).attr("selected") =="selected"){
					$(this).removeAttr("selected");
				}
				if($(this).attr("value") ==""){
					$(this).attr("selected","selected");
				}
			});
		});
	});
}
function cleanArea(){
	$("#areaId").val("");
	$("#area").val("");
	$("#storeId").find("option").each(function(){
		if($(this).val() !=""){
			$(this).remove();
		}
	});
	$("#floorId").find("option").each(function(){
		if($(this).val() !=""){
			$(this).remove();
		}else{
			$(this).attr("selected","selected");
		}
	});
}
function cleanSignBy(){
	$("#signBy").val("");
	$("#signById").val("");
}
function cleanCreateBy(){
	$("#createBy").val("");
	$("#createBy").val("");
}
